package com.wang.controller;

import com.wang.param.weixin.RegisterThirdUserRequest;
import com.wang.param.weixin.WxBindingPhoneRequest;
import com.wang.reponse.LoginResponse;
import com.wang.result.BaseResponse;
import com.wang.result.ResultUtils;
import com.wang.user.service.user.UserService;

import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;




/**
 * 微信缓存表 前端控制器
 */
@Slf4j
@RestController("WeChatFrontController")
@RequestMapping("/wechat")
@Api(tags = "微信登录")
public class WeChatController {

    @Autowired
    private UserService userService;

    /**
     * 微信登录小程序授权登录
     */
    @ApiOperation(value = "微信登录小程序授权登录")
    @RequestMapping(value = "/authorize/program/login", method = RequestMethod.POST)
    public BaseResponse<LoginResponse> programLogin(@RequestParam String code, @RequestBody @Validated RegisterThirdUserRequest request){
        return ResultUtils.success(userService.weChatAuthorizeProgramLogin(code, request));
    }


    /**
     * 微信注册绑定手机号
     */
    @ApiOperation(value = "微信注册绑定手机号")
    @RequestMapping(value = "/register/binding/phone", method = RequestMethod.POST)
    public BaseResponse<LoginResponse> registerBindingPhone(@RequestBody @Validated WxBindingPhoneRequest request){
        return ResultUtils.success(userService.registerBindingPhone(request));
    }


}



